﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web;

namespace Fjaspx.Common
{
    /// <summary>
    /// 用于所有的环境的缓存
    /// </summary>
    public static class CacheHelper
    {
        public static bool IsNull(string cacheName)
        {
            return HttpRuntime.Cache[cacheName] == null;
        }
        public static void SetCache(string cacheName, object value, double minutes)
        {
           HttpRuntime.Cache.Insert(cacheName, value, null, DateTime.MaxValue, TimeSpan.FromMinutes(minutes));
        }
        public static void SetCache(string cacheName, object value)
        {
           HttpRuntime.Cache.Insert(cacheName, value);
        }
        public static void Delete(string cacheName)
        {
            if (!IsNull(cacheName)) HttpRuntime.Cache.Remove(cacheName);
        }
        public static object GetCache(string cacheName)
        {
            return HttpRuntime.Cache.Get(cacheName);
        }
        public static void Update(string cacheName, object newValue, double minutes)
        {
            if (IsNull(cacheName))
            {
                SetCache(cacheName, newValue, minutes);
                return;
            }
            HttpRuntime.Cache[cacheName] = newValue;
        }
    }
}
